<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-store, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
    <META HTTP-EQUIV="expires" CONTENT="0">
    <title>父工单管理</title>
    <link rel="stylesheet" type="text/css" href="./css/main.css" />
    <link rel="stylesheet" type="text/css" href="./layui/css/layui.css" />
    <link rel="stylesheet" type="text/css" href="./css/layuiAdminTheme.css" />
    <style type="text/css">
        .layui-form-label {
            width: auto !important;
        }

        .createTime,
        .operation span:first-of-type {
            color: #1990FF;
        }

        .operation span:last-of-type {
            color: #F5222D;
        }

        .pageNav {
            margin: 0 auto;
            width: fit-content;
        }

        .pageNav a,
        .operation span {
            cursor: pointer;
            display: inline-block;
        }

        .operation{
            overflow: hidden;
            text-overflow:ellipsis;
            white-space: nowrap;
        }

        cite {
            cursor: default;
        }

        td
        {
            white-space: nowrap;
            text-align: center;
        }


    </style>
</head>
<body>
<script src="./js/main.js" charset="utf-8"></script>
<!--    <script src="https://cdn.jsdelivr.net/npm/jquery" charset="utf-8"></script>-->
<script src="./layui/layui.js" charset="utf-8"></script>
<script src="./js/jQuery.main.js"></script>
<script src="./js/xm-select.js" type="text/javascript" charset="utf-8"></script>
<script src="./js/echarts.js" charset="utf-8"></script>

<form class="layui-form" action="" lay-filter="data">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">搜索：</label>
            <input type="text" name="lotNo" id="lotNo" class="layui-input" style="width: 10em;" placeholder="LotNo" value="">
        </div>
        <div class="layui-inline">
            <input type="text" name="pinName" id="pinName" class="layui-input" style="width: 14em;" placeholder="品名/PN" value="">
        </div>
        <div class="layui-inline">
            <input type="text" name="productType" id="productType" class="layui-input" style="width: 14em;" placeholder="产品类型" value="">
        </div>
        <div class="layui-inline">
            <input type="text" name="createBy" id="createBy" class="layui-input" style="width: 8em;" placeholder="创建人" value="">
        </div>
        <div class="layui-inline">
            <input id="orderDept" type="text" name="orderDept" class="layui-input" style="width: 8em;" placeholder="所属部门" value="" onclick="isAdminOfOrder()">
        </div>
        <div class="layui-inline">
            <select id="status" type="text" name="status" class="layui-input" style="width: 8em;" lay-filter="status">
                <option value="">请选择状态...</option>
                <option value="0">进行中</option>
                <option value="1">已完成</option>
            </select>
        </div>
        <div class="layui-inline">
            <input type="text" name="displayLength" class="layui-input" style="display: none;" placeholder="每页页数" value="10">
            <button id="searchBtn" type="submit" class="layui-btn" lay-submit="" lay-filter="searchBtn">查询工单</button>
        </div>
        <div class="layui-inline" style="float: right">
            <button id="erpDown" type="button" class="layui-btn layui-bg-cyan" lay-filter="erpDown"><i class="layui-icon">&#xe654;</i>  EPR获取工单</button>
        </div>
    </div>
</form>

<table class="layui-table" lay-skin="line" id="orderTable">
    <thead>
    <tr>
        <!--<th><input type="checkbox" id="select" onclick="selectAll()" /></th>-->
        <th style="text-align: center">工单编号</th>
        <th style="text-align: center">品名/PN</th>
        <th style="text-align: center">创建时间
            <span class="layui-table-sort layui-inline">
              <i class="layui-edge layui-table-sort-asc" title="升序" onclick="sortTime('asc')"></i>
              <i class="layui-edge layui-table-sort-desc" title="降序" onclick="sortTime('desc')"></i>
            </span>
        </th>
        <th style="text-align: center">产品类型</th>
        <th style="text-align: center">总数</th>
        <th style="text-align: center">子工单接收</th>
        <th style="text-align: center">子工单数量</th>
        <th style="text-align: center">创建人</th>
        <th style="text-align: center">工单状态</th>
        <th style="text-align: center">操作</th>
    </tr>
    </thead>
    <tbody id="parentData"></tbody>
</table>
<div style="display: flex;">
    <!--
          <button type="button" class="layui-btn layui-btn-xs" style="background: #F5222D;" onclick="deleteOrder()">批量删除</button>
    -->
    <div style="flex: 1">
        <div class="pageNav">
          <span class="layui-breadcrumb" lay-separator="-">
            <a class="fristPage">首页</a>
            <a class="lastPage">上一页</a>
            <a><cite>第<span id="page"></span>页</cite></a>
            <a class="totalPage"><cite>共<span id="total">0</span>页</cite></a>
            <a class="nextPage">下一页</a>
            <a class="endPage">尾页</a>
          </span>
        </div>
    </div>
</div>
<div id="infoDiv"  class="site-text" style="margin: 5%; display: none"></div>
<div id="erpOrderInfo"  class="site-text" style="margin: 5%; display: none"></div>

<script type="text/javascript">
    var displayStart = 1;
    var endPage = null;
    var layer = layui.layer;
    var form = null;
    var list = null;
    var table=layui.table;


    //排序
    function sortTime(date) {
        search(1,date)
    }

    layui.use(['form', 'element'], function() {
        form = layui.form;
        search(1);
        form.on('submit(searchBtn)', function() {
            search(1);
            return false;
        });
        $('.fristPage').click(function() {
            search(1);
            return false;
        });
        $('.lastPage').click(function() {
            search((displayStart > 1 ? displayStart - 1 : 1));
            return false;
        });
        $('.nextPage').click(function() {
            search((displayStart < endPage ? displayStart + 1 : endPage));
            return false;
        });
        $('.endPage').click(function() {
            search(endPage);
            return false;
        })
    })

    function downFromErp(data){
        var accept=$('#defaultAccept').val();
        let confirm1=layer.confirm('确认导入吗？</br>将以每张子工单接收<b style="color: red">'+accept+'</b>数量拆分工单!', {
            btn: ['确定','取消']},function(){
            console.log(data);
            //loading层遮罩
            var index = layer.load(3, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $.ajax({
                url: url + '/parent-order/addFromKingdee',
                method: 'POST',
                contentType: 'application/json',
                data: JSON.stringify({
                    fbillNo:data.fbillNo,
                    fspecification:data.fspecification,
                    fqty:data.fqty,
                    fmaterialId:data.fmaterialId,
                    fprdOrgId:data.fprdOrgId,
                    userId:sessionStorage.getItem('userId'),
                    acceptAmount:accept
                }),
                success: function(res) {
                    if(res.code==400){
                        //关闭loading弹出提示信息
                        layer.close(index)
                        layer.alert(res.msg, {
                            icon: 2,
                            skin: 'layer-ext-demo' //见：扩展说明
                        })
                    }else{
                        //关闭loading弹出提示信息
                        layer.close(index)
                        layer.alert(res.msg, {
                            icon: 1,
                            skin: 'layer-ext-demo' //见：扩展说明
                        })
                    }
                }
            })
            layer.close(confirm1);
        },function () {
            layer.close(confirm1);
        })
    }

    $('#erpDown').click(function () {
        var isSetting=false;
        $("#erpOrderInfo").empty();
        var trs='';
        trs+="<div style='margin-top:-3%;'>"
        trs+="<div style='float: left'>" +
            "<span>以下数据为ERP中生产订单(不包括外购订单)中的数据,共为你找到 <span id='orderAmount' style='color: red'>" +
            "</span> 条单据.(只获取7月1号以后的生产单据！)</span>" +
            "</div>";
        trs+="<div style='float: right;'>" +
            "<input onkeyup=\"value=value.replace(/[^\\d]/g,'')\" type='text' id='defaultAccept' class='layui-input' style='display: none;width: 10em' placeholder='每张子工单接收量' value='15000' autocomplete='off'>" +
            "</div>" ;
        trs+="<div style='float: right;'>" +
            "<button id='settingAccept' type='button' class='layui-btn'>设置子工单分配数量</button>" +
            "</div>" ;
        trs+="</div>"
        trs+="<input type='text' id='displayLength' class='layui-input' style='display: none;' placeholder='每页页数' value='10'>" ;
        trs+="<table class='layui-table' lay-skin=''>" +
            "    <thead>" +
            "    <tr>" +
            "        <!--<th><input type=\"checkbox\" id=\"select\" onclick=\"selectAll()\" /></th>-->" +
            "        <th style='text-align: center'>生产订单号/FbillNo</th>" +
            "        <th style='text-align: center'>生产数量/Fqty</th>" +
            "        <th style='text-align: center'>产品型号/Fspecification</th>" +
            "        <th style='text-align: center'>物料ID/FMaterialId</th>" +
            "        <th style='text-align: center'>单据日期/FDate</th>" +
            "        <th style='text-align: center'>计划开工日期/FplanStartDate</th>" +
            "        <th style='text-align: center'>生产组织ID/FprdOrgId</th>" +
            "        <th style='text-align: center'>操作</th>" +
            "    </tr>" +
            "    </thead>" +
            "    <tbody id='erpTbody'></tbody>" +
            "</table>"
        //加载折叠面板
        $("#erpOrderInfo").append(trs);
        //layui.element.init()
        layer.open({
            type: 1,
            title: 'ERP生产订单列表——本部门',
            maxmin: true,
            shadeClose: true, //点击遮罩关闭层
            area : ['75%' , '75%'],
            content: $('#erpOrderInfo'),
            success:function(){
                //数据写入表格
                $.ajax({
                    url: url + '/parent-order/queryKingdee',
                    method: 'POST',
                    contentType: 'application/json',
                    async:false,
                    data: JSON.stringify({
                        displayStart :1,
                        displayLength : $('#displayLength').val(),
                        userId:sessionStorage.getItem('userId')
                    }),
                    success: function(res) {
                        console.log(res.data)
                        if(res.code==400){
                            layer.msg(res.msg)
                        }else{
                            $('#erpTbody').empty();
                            var totalAmount=0;
                            for (var i = 0; i < res.data.length; i++) {
                                totalAmount=res.data[i].total;
                                $('#erpTbody').append(
                                    "<tr>" +
                                    "<td style='color: red'>" + res.data[i].fbillNo + "</td>" +
                                    "<td class='createTime'>" + res.data[i].fqty + "</td>" +
                                    "<td style='color: red'>" + res.data[i].fspecification + "</td>" +
                                    "<td class='createTime'>" + res.data[i].fmaterialId + "</td>" +
                                    "<td>" + res.data[i].fdate.replace('T',' ')+ "</td>" +
                                    "<td>" + res.data[i].fplanStartDate.replace('T',' ')+ "</td>" +
                                    "<td>" + res.data[i].fprdOrgId+ "</td>" +
                                    "<td class='operation'>" +
                                        "<button type='button' class='layui-btn layui-bg-cyan layui-btn-sm' onclick='downFromErp("+JSON.stringify(res.data[i])+")'>导入到本系统</button>" +
                                        // "<button type='button' class='layui-btn layui-bg-cyan layui-btn-sm' onclick='downFromErp(\"" + res.data[i].fbillNo + "\",\"" + res.data[i].fspecification + "\",\"" + res.data[i].fqty + "\",\"" + res.data[i].fmaterialId + "\",\"" + res.data[i].fprdOrgId + "\")'>导入到本系统</button>" +
                                    "</tr>"
                                );
                            }
                            $('#orderAmount').html(totalAmount)
                        }
                    }
                })
            },
            end:function () {
                $('#erpOrderInfo').css('display','none').empty();
                search(1);
            }
        });

        //设置按钮触发方法
        $("#settingAccept").click(function () {
            if(isSetting==false){
                //显示输入框
                $('#defaultAccept').attr('style','width: 10em')
                //按钮变样
                $("#settingAccept").empty().html("使用默认值").addClass('layui-btn-danger')
                isSetting=true;
            }else {
                //隐藏并恢复默认值
                $('#defaultAccept').attr('style','display: none;width: 10em').val('15000')
                //按钮恢复
                $("#settingAccept").empty().html("设置子工单分配数量").removeClass('layui-btn-danger')
                isSetting=false;
            }
        })
    })

    function listInfo(index) {
        layer.open({
            type: 1,
            skin: 'layui-layer-rim',
            area: ['700px', '770px'],
            title: '工单详情',
            content: `
            <div style=" margin: 10px"></div>
            <div class="layui-row layui-col-space10">
                 <div class="layui-row">
                   <div class="layui-col-md6">
                     <label class="layui-form-label">工单号/LotNo：</label>
                        <div class="layui-input-inline " style="width: 15em"  >
                        <input id="lotNoOfInfo" type="text" name="lotNoOfInfo"  class="layui-input" style="width: 15em !important;" readonly="readonly">
                        </div>
                   </div>
                   <div class="layui-col-md6">
                     <label class="layui-form-label">品名/PN：</label>
                        <div class="layui-input-inline " style="width: 15em"  >
                        <input id="pinNameOfInfo" type="text" name="pinNameOfInfo"  class="layui-input" style="width: 15em !important;" readonly="readonly">
                        </div>
                   </div>
                   </div>
            </div>

            <div style=" margin: 10px"></div>
            <div class="layui-row">
              <div class="layui-col-md4">
                <label class="layui-form-label">总数：</label>
                   <div class="layui-input-inline " style="width: 7em"  >
                   <input id="totalAmount" type="text" name="totalAmount"  class="layui-input" style="width: 7em !important;" readonly="readonly">
                   </div>
              </div>
              <div class="layui-col-md4">
                <label class="layui-form-label">单位:</label>
                   <div class="layui-input-inline " style="width: 7em"  >
                   <input id="unit" type="text" name="unit"  class="layui-input" style="width: 5em !important;" readonly="readonly">
                   </div>
              </div>
              <div class="layui-col-md4">
                <label class="layui-form-label">产品类型:</label>
                   <div class="layui-input-inline " style="width: 7em"  >
                   <input id="productTypeOfInfo" type="text" name="productTypeOfInfo"  class="layui-input" style="width: 7em !important;" readonly="readonly">
                   </div>
              </div>
            </div>

            <div class="layui-row" >
            <div class="layui-col-md12" style="margin: 10px;width: 30em">
                <label class="layui-form-label">子工单接收数量：</label>
                   <div class="layui-input-inline " style="width: 15em"  >
                   <input id="acceptAmount" type="text" name="acceptAmount"  class="layui-input" style="width: 15em !important;" readonly="readonly">
                   </div>
              </div>
            </div>

            <div class="layui-row" >
                <div class="layui-col-md12"><label class="layui-form-label">子工单数量：</label>
                   <div class="layui-input-inline " style="width: 15em" >
                   <input id="childrenNum" type="text" name="childrenNum"  class="layui-input" style="width: 15em !important;" readonly="readonly"></div>
                   <div class="layui-input-inline " style="width: 15em" >
                   <button style="color:#049ce3;" id="infoView" class="layui-btn layui-btn-primary layui-border-blue" lay-submit="" lay-filter="infoView">
                    <b>●查看子工单明细</b></button></div>
                </div>
            </div>

            <div class="layui-row" style="margin: 10px">
                <div class="layui-col-md6">
                <label class="layui-form-label">物料编码：</label>
                <div class="layui-input-inline " style="width: 15em"  >
                <input id="materialCode" type="text" name="materialCode"  class="layui-input" style="width: 15em !important;" readonly="readonly">
                </div></div>
                <div class="layui-col-md6">
                <label class="layui-form-label">物料名称：</label>
                <div class="layui-input-inline " style="width: 15em"  >
                <input id="materialName" type="text" name="materialName"  class="layui-input" style="width: 14.5em !important;" readonly="readonly">
                </div></div>
            </div>
            <div class="layui-row" style="margin: 10px">
                <div class="layui-col-md6">
                <label class="layui-form-label">创建时间：</label>
                <div class="layui-input-inline " style="width: 15em"  >
                <input id="createTime" type="text" name="createTime"  class="layui-input" style="width: 15em !important;" readonly="readonly">
                </div></div>
                <div class="layui-col-md6">
                <label class="layui-form-label">创建人：</label>
                <div class="layui-input-inline " style="width: 15em"  >
                <input id="createByOfInfo" type="text" name="createByOfInfo"  class="layui-input" style="width: 15.5em !important;" readonly="readonly">
                </div></div>
            </div>
             <div class="layui-row" style="margin: 10px">
                <div class="layui-col-md12">
                <label class="layui-form-label">所需工序：</label>
                <div class="layui-input-inline " style="width: 15em"  >
                <input id="processName" type="text" name="createTime"  class="layui-input" style="width: 25em !important;" readonly="readonly">
                </div></div>
            </div>

            <div id="amountECharts" align="center" style="margin: 20px; width: 570px;height:325px;background-color: #FBFBFB"></div>
          `,

            success: function(){
                //数据显示
                $.ajax({
                    url: '/parent-order/listParentInfo/'+index,
                    type: 'GET',
                    contentType: 'application/json',
                    success: function (res) {
                        if(res.code==200){
                            $('#lotNoOfInfo').val(res.data.lotNo);
                            $('#pinNameOfInfo').val(res.data.pinName);
                            $('#totalAmount').val(res.data.totalAmount);
                            $('#unit').val(res.data.unit);
                            $('#productTypeOfInfo').val(res.data.productType);
                            $('#acceptAmount').val(res.data.acceptAmount);
                            $('#childrenNum').val(res.data.childrenNum);
                            $('#materialCode').val(res.data.materialCode);
                            $('#materialName').val(res.data.materialName);
                            $('#createTime').val(res.data.createTime);
                            $('#createByOfInfo').val(res.data.createBy);
                            $('#processName').val(res.data.processName);
                        }
                    }
                })
                //饼图数据载入
                $.ajax({
                    url: '/parent-order/getChartData/'+index,
                    type: 'GET',
                    contentType: 'application/json',
                    success: function (res) {
                        var msg;
                        if(res.data.over==true){
                            msg=index+" :工单已完结, 当前良率: "+res.data.nowPassRate;
                        }else{
                            msg=index+" :工单未完结, 当前良率: "+res.data.nowPassRate;
                        }
                        var amountChart = echarts.init(document.getElementById('amountECharts'));
                        var option = {
                            title: {
                                text: '数量统计',
                                subtext: msg,
                                left: 'center'
                            },
                            tooltip: {
                                trigger: 'item'
                            },
                            toolbox: {
                                show: true,
                                feature: {
                                    mark: { show: true },
                                    dataView: { show: true, readOnly: false },
                                    restore: { show: true },
                                    saveAsImage: { show: true }
                                }
                            },
                            legend: {
                                orient: 'vertical',
                                left: 'left'
                            },
                            color:['#5FB878','#FF5722','#FFB800'],
                            series: [
                                {
                                    name: '各项数据明细',
                                    type: 'pie',
                                    radius: '50%',
                                    data: [
                                        {
                                            value: res.data.amount,
                                            name: '良品数'
                                        },
                                        {
                                            value: res.data.badAmount,
                                            name: '不良数'
                                        },
                                        {
                                            value: res.data.missingAmount,
                                            name: '剩余未报或缺数'
                                        }
                                    ],
                                    emphasis: {
                                        itemStyle: {
                                            shadowBlur: 10,
                                            shadowOffsetX: 0,
                                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                                        }
                                    }
                                }
                            ]
                        };
                        amountChart.setOption(option);
                    }
                })
            }
        });
        //折叠面板生效
        layui.use('element', function(){
            var element = layui.element;
            //…
        });
        form.on('submit(infoView)', function() {
            $("#infoDiv").empty();
            var trs='';
            $.ajax({
                url: url +'/parent-order/listChildOrderInfo',
                method: 'POST',
                contentType: 'application/json',
                data: JSON.stringify({
                    lotNo:index,
                    childNum:""
                }),
                success: function (res) {
                    //获取弹出层数据
                    if(res.code==200){
                        trs+='<div class="layui-inline"> <label class="layui-form-label" ><b>' +
                            '<svg id="helpTips" t="1653441731691" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3087" width="15" height="15"><path d="M512 1024A512 512 0 1 1 512 0a512 512 0 0 1 0 1024z m-32.128-192.384c41.152 0 74.56-30.528 74.56-68.16s-33.408-68.16-74.56-68.16-74.56 30.528-74.56 68.16 33.344 68.16 74.56 68.16z m0-639.232c-123.52 0-223.68 91.584-223.68 204.48H368c0-56.448 50.048-102.272 111.808-102.272 61.76 0 111.808 45.76 111.808 102.272 0 38.848-23.744 72.64-58.624 89.984a224.256 224.256 0 0 0-43.136 30.784l-1.152 1.024a169.152 169.152 0 0 0-6.016 5.76l-1.216 1.216-1.6 1.6v0.128a201.664 201.664 0 0 0-44.352 70.016 190.08 190.08 0 0 0-10.56 52.992h-1.024l-0.128 12.288c0-4.16 0.832-8.128 1.088-12.288h110.848l-0.064 12.288c0-38.848 23.68-72.64 58.56-89.92 19.968-10.88 37.952-24.576 53.248-40.448v-0.064a194.048 194.048 0 0 0 56-135.296c0.064-112.96-100.096-204.544-223.616-204.544z" p-id="3088"></path></svg>     共有'+res.data.length+'条子工单： </b></label>' +
                            ' <input type="text" name="childNum" id="childNum" class="layui-input" style="width: 15em;" placeholder="子工单工单号" value="">' +
                            '</div>' +
                            '<div class="layui-inline">' +
                            '    <button id="searchChildBtn" type="submit" class="layui-btn" lay-submit="" lay-filter="searchChildBtn">查询子工单</button>' +
                            '</div>'
                        trs+='<div class="layui-collapse" style="margin: 15px">'
                        for (var i = 0; i < res.data.length; i++) {
                            //获取layui-colla-item的内容
                            trs+='<div class="layui-colla-item">'
                            var str=childStatus(res.data[i].orderNum,res.data[i].orderStatus)
                            trs+=str
                            //获取layui-colla-content的内容
                            trs+='  <div class="layui-colla-content"> '
                            trs += '<ul class="Content_list clearfix">';
                            // trs += '<label class="label_name" style="line-height: 2"><b style="color: #f5222d">——上报记录'+j+':             </b></label>';
                            trs += '<li style="line-height:2.5"><label class="label_name"><b>●  工单号:             </b></label><span style="color: #1890ff">'+res.data[0].orderNum+'</span></li>';
                            trs += '<li style="line-height:2.5"><label class="label_name"><b>●  已经完成的工序:                  </b></label><span style="color: #1890ff">'+res.data[i].overProcess+'</span></li>';
                            trs += '<li style="line-height:2.5"><label class="label_name"><b>●  工单状态:             </b></label><span style="color: #1890ff">'+isOrderStatus(res.data[i].orderStatus)+'</span></li>';
                            trs += '<li style="line-height:2.5"><label class="label_name"><b>●  当前工序:             </b></label><span style="color: #1890ff">'+res.data[i].nowProcess+'</span></li>';
                            trs += '<li style="line-height:2.5"><label class="label_name"><b>●  当前工序执行人:             </b></label><span style="color: #1890ff">'+res.data[i].nowWorker+'</span></li>';
                            trs += '<li style="line-height:2.5"><label class="label_name"><b>●  计划数量:                 </b></label><span style="color: #1890ff">'+res.data[i].amountPlan+'</span></li>';
                            trs += '<li style="line-height:2.5"><label class="label_name"><b>●  结算良品数(含余数录入):                    </b></label><span style="color: #1890ff">'+res.data[i].amount+'</span></li>';
                            trs += '<li style="line-height:2.5"><label class="label_name"><b>●  总不良数:                    </b></label><span style="color: #1890ff">'+res.data[i].badAmount+'</span></li>';
                            trs += '</ul>';
                            trs+='<div style="margin: 5px" align="center"><h4><b> 各工序上报数量明细 </b></h4></div>'
                            //开始生成表格
                            trs+='<div align="center"><table style="margin: 10px" border="2" width="510px" height="80px">'
                            //生成表头
                            trs+=' <tr>'+
                                '      <th>工序名/数据项</th>'
                            for(var j=0;j<res.data[i].processName.length;j++){
                                trs+='  <th>'+res.data[i].processName[j]+'</th>'
                            }
                            trs+='  <th>余数录入</th>'
                            trs+='  <th>最终结算</th></tr>'
                            //生成良品数行
                            trs+='  <tr>' +
                                '    <td>良品数</td> '
                            for(var k=0;k<res.data[i].reportAmount.length;k++){
                                trs+='    <td>'+res.data[i].reportAmount[k]+'</td>'
                            }
                            trs+=' <td>'+"+"+res.data[i].supplyAmount+'</td>'
                            var allTotalAmount=Number(res.data[i].reportAmount[res.data[i].reportAmount.length-1])+Number(res.data[i].supplyAmount);
                            trs+=' <td>'+allTotalAmount+'</td></tr>'
                            //生成不良品数行
                            trs+='  <tr>' +
                                '    <td>不良品数</td>'
                            for(var l=0;l<res.data[i].reportBadAmount.length;l++){
                                trs+='    <td>'+res.data[i].reportBadAmount[l]+'</td>'
                            }
                            trs+=' <td>'+"-"+res.data[i].supplyAmount+'</td>'
                            trs+='<td>'+res.data[i].badAmount+'</td></tr>'
                            trs+='  </tr>'
                            
                            trs+='</table></div>' +
                            '</div>' +
                            '</div>'
                        }
                        trs+='</div>';
                        //trs+='<div align="center" style="margin: 10px"><button class="layui-btn layui-btn-danger" onclick=""><b><i class="layui-icon">&#xe605;</i></b></button></div>';
                    }
                    //加载折叠面板
                    $("#infoDiv").append(trs);
                    layui.element.init()
                    layer.open({
                        type: 1,
                        title: '子工单详情',
                        maxmin: true,
                        shadeClose: true, //点击遮罩关闭层
                        area : ['700px' , '650px'],
                        content: $('#infoDiv'),
                        end:function () {
                            $('#infoDiv').css('display','none')
                        }
                    });
                    //提示信息
                    $(function(){
                        var tips;
                        $('#helpTips').on({
                            mouseenter:function(){
                                var that = this;
                                tips =layer.tips('●蓝色工单表示进行中，黄色表示待审核，绿色表示已经完结</br>' +
                                    '●工序全部完结的子工单良品数和不良数才会纳入到父工单中进行统计</br>' +
                                    '●更多关于子工单详细信息前往工单报工管理——>管理&上报——>找到对应子工单——>点击详情查看', '#helpTips', {
                                    tips: [4, '#3595CC'],
                                    time: 30000
                                });
                            },
                            mouseleave:function(){
                                layer.close(tips);
                            }
                        });
                    })
                    //查询按钮
                    $("#searchChildBtn").click(function(){
                        layer.msg("暂未开放")
                    });
                }
            })
        })
    }

    function edit(index) {
        //先判断权限
        $.ajax({
            url: '/sys-user/getAdminLevel/'+sessionStorage.getItem('userId'),
            method: 'GET',
            contentType: 'application/json',
            success: function (res) {
                if (res.code===200){
                    layer.open({
                        type: 1,
                        skin: 'layui-layer-rim',
                        area: ['400px', 'auto'],
                        title: '工单编辑',
                        content: `
                <form class="layui-form" action="" lay-filter="change">
                <div style=" margin: 15px"></div>
                <input id="id" type="text" name="id"  lay-verify="required" class="layui-input" style="display:none">

                <div><label class="layui-form-label">工单号/lotNo：</label>
                <div class="layui-input-inline " style="width: 15em">
                <input id="lotNo" type="text" name="lotNo" placeholder="输入工单号/lotNo" lay-verify="required" class="layui-input" style="width: 16em !important;">
                </div></div>

                <div><label class="layui-form-label" style="margin: 10px 0;">品名：</label>
                <div class="layui-input-inline " style="width: 15em"  >
                <input id="pinName" type="text" name="pinName" placeholder="输入品名" lay-verify="required" class="layui-input" style="margin: 10px 0; width: 19.5em !important;">
                </div></div>

                <div>
                <svg t="1653096172503" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3015" width="20" height="20"><path d="M832 1024H192a84.48 84.48 0 0 1-84.48-84.48V464A84.48 84.48 0 0 1 192 379.52h640a84.48 84.48 0 0 1 84.48 84.48v473.6A84.48 84.48 0 0 1 832 1024zM192 444.16a19.84 19.84 0 0 0-19.84 19.84v473.6A19.84 19.84 0 0 0 192 960h640a19.84 19.84 0 0 0 19.84-19.84V464a19.84 19.84 0 0 0-19.84-19.84z" fill="#323333" p-id="3016"></path><path d="M732.16 432.64a26.88 26.88 0 0 1-28.16-26.88V256a197.12 197.12 0 0 0-392.32 0v149.76a26.88 26.88 0 0 1-27.52 26.88 27.52 27.52 0 0 1-28.16-26.88V256a251.52 251.52 0 1 1 503.04 0v149.76a26.88 26.88 0 0 1-26.88 26.88z" fill="#323333" p-id="3017"></path><path d="M511.36 662.4m-90.24 0a90.24 90.24 0 1 0 180.48 0 90.24 90.24 0 1 0-180.48 0Z" fill="#323333" p-id="3018"></path><path d="M512 858.24a32.64 32.64 0 0 1-32.64-32.64v-112.64a32.64 32.64 0 0 1 32.64-32.64 32 32 0 0 1 32 32.64v112.64a32 32 0 0 1-32 32.64z" fill="#323333" p-id="3019"></path></svg>
                <label class="layui-form-label" style="color:#f50606;">总数量：</label>
                <div class="layui-input-inline " style="width: 15em">
                <input id="totalAmount" type="text" name="totalAmount" placeholder="输入总数量" lay-verify="required" class="layui-input" style="margin-bottom: 10px;width: 16.5em !important;">
                </div></div>

                <div>
                <div class="layui-input-inline "><svg t="1653096172503" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3015" width="20" height="20"><path d="M832 1024H192a84.48 84.48 0 0 1-84.48-84.48V464A84.48 84.48 0 0 1 192 379.52h640a84.48 84.48 0 0 1 84.48 84.48v473.6A84.48 84.48 0 0 1 832 1024zM192 444.16a19.84 19.84 0 0 0-19.84 19.84v473.6A19.84 19.84 0 0 0 192 960h640a19.84 19.84 0 0 0 19.84-19.84V464a19.84 19.84 0 0 0-19.84-19.84z" fill="#323333" p-id="3016"></path><path d="M732.16 432.64a26.88 26.88 0 0 1-28.16-26.88V256a197.12 197.12 0 0 0-392.32 0v149.76a26.88 26.88 0 0 1-27.52 26.88 27.52 27.52 0 0 1-28.16-26.88V256a251.52 251.52 0 1 1 503.04 0v149.76a26.88 26.88 0 0 1-26.88 26.88z" fill="#323333" p-id="3017"></path><path d="M511.36 662.4m-90.24 0a90.24 90.24 0 1 0 180.48 0 90.24 90.24 0 1 0-180.48 0Z" fill="#323333" p-id="3018"></path><path d="M512 858.24a32.64 32.64 0 0 1-32.64-32.64v-112.64a32.64 32.64 0 0 1 32.64-32.64 32 32 0 0 1 32 32.64v112.64a32 32 0 0 1-32 32.64z" fill="#323333" p-id="3019"></path></svg>
                </div><label class="layui-form-label" style="color:#f50606;">子工单/ACCEPT：</label>
                <div class="layui-input-inline " style="width: 10em">
                <input id="acceptAmount" type="text" name="acceptAmount" placeholder="输入子工单接收数量" lay-verify="required" class="layui-input" style="width: 12.5em !important;"></div>
                </div>

                <div>
                <label class="layui-form-label" style="margin: 10px 0;">单位：</label>
                <div class="layui-input-inline " style="width: 15em" >
                <input id="unit" type="text" name="unit" placeholder="输入单位" lay-verify="required" class="layui-input" style="margin: 10px 0; width: 20em !important;">
                </div></div>

                <div>
                <label class="layui-form-label" style="margin: 10px 0;">产品类型：</label>
                <div class="layui-input-inline " style="width: 15em" >
                <input id="productType" type="text" name="productType" placeholder="输入产品类型" lay-verify="required" class="layui-input" style="margin: 10px 0; width: 18em !important;">
                </div></div>

                <div>
                <label class="layui-form-label" style="margin: 10px 0;">下达车间：</label>
                <div class="layui-input-inline " style="width: 15em">
                <input id="workshop" type="text" name="workshop" placeholder="输入下达车间" lay-verify="required" class="layui-input" style="margin: 10px 0; width: 18em !important;"></div></div>

                <div align="center" style="margin:30px 0">
                 <button id="submit" type="submit" class="layui-btn" lay-submit="" lay-filter="changeBtn" >点击修改</button>
                 <button type="button" class="layui-btn layui-btn-danger" onclick="layer.close(layer.index)">取消编辑</button>
                </div>
                </form>
          `,

                        success: function(){
                            $('#acceptAmount').attr('readonly','readonly')
                            $('#totalAmount').attr('readonly','readonly')
                            $.ajax({
                                url: '/parent-order/getParentInfo/'+index,
                                type: 'GET',
                                contentType: 'application/json',
                                success: function (res) {
                                    if(res.code==200){
                                        form.val("change",{
                                            "id":res.data.id,
                                            "lotNo":res.data.lotNo,
                                            "pinName":res.data.pinName,
                                            "totalAmount":res.data.totalAmount,
                                            "acceptAmount":res.data.acceptAmount,
                                            "unit":res.data.unit,
                                            "productType":res.data.productType,
                                            "workshop":res.data.workshop,
                                        })
                                        form.render()
                                    }
                                }
                            })
                        }
                    });
                }else {
                    layer.msg("权限不足！")
                }
            }
        })

        $('#acceptAmount').click(function () {
            layer.msg("此项不允许更改")
        })
        $('#totalAmount').click(function (){
            layer.msg("此项不允许更改")
        })

        //提交方法
        form.on('submit(changeBtn)', function(data) {
            let confirm1=layer.confirm('确认信息无误？</br>修改后关联的子工单也会更新!', {
                btn: ['确定','再看看']},function(){
                console.log("校验通过，准备提交");
                var data = form.val("change");
                console.log(data);
                $.ajax({
                    url: url + '/parent-order/update',
                    method: 'POST',
                    contentType: 'application/json',
                    async: false,
                    data: JSON.stringify(data),
                    success: function(res) {
                        console.log(res);
                        if (res.code == 200) {
                            parent.layer.alert(res.msg, {
                                icon: 1,
                                end: function(){
                                    location.reload();
                                }
                            });
                        }else {
                            parent.layer.alert(res.msg, {
                                icon: 2,
                            });
                        }
                    }
                })
                layer.close(confirm1);
            },function () {
                layer.close(confirm1);
            })
            return false;
        })

    }

    function deleteOrder(index) {
        $.ajax({
            url: '/sys-user/getAdminLevel/'+sessionStorage.getItem('userId'),
            method: 'GET',
            contentType: 'application/json',
            success: function (res) {
                if (res.code===200){
                    let confirm1=layer.confirm('确定删除改工单？</br>删除后关联的子工单也会删除!', {
                            btn: ['确定','取消']},function(){
                            $.ajax({
                                url: '/parent-order/delete/'+index,
                                type: 'DELETE',
                                contentType: 'application/json',
                                success: function (res) {
                                    layer.alert(res.msg, {
                                        icon: 1,
                                        skin: 'layer-ext-demo',
                                        end: function(){
                                            location.reload();
                                        }
                                    })
                            }
                        })
                        layer.close(confirm1);
                    },function () {
                        layer.close(confirm1);
                    })
                }else{
                    layer.alert("父工单删除后会删除所有子工单！<br /> 有需求请联系管理员!", {
                        title:"警告",
                        icon: 0,
                        skin: 'layer-ext-demo' //见：扩展说明
                    })
                }
            }
        })

    }
    function search(index,sort) {
        //loading层遮罩
        var loading = layer.load(3, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });
        if (!index) var index = displayStart;
        var data = form.val('data');
        data.displayStart = index;
        data.userId= sessionStorage.getItem('userId')
        data.status=$('#status').val();
        data.sortStatus=sort;
        $.ajax({
            url: url + '/parent-order/listParent',
            method: 'POST',
            contentType: 'application/json',
            data: JSON.stringify(data),
            success: function(res) {
                layer.close(loading)
                //total=Math.ceil(res.data.records.length/10);
                $('#parentData').empty();
                displayStart = res.data.current;
                endPage = res.data.pages;
                list = res.data.records;
                for (var i = 0; i < res.data.records.length; i++) {
                    $('#parentData').append(
                        "<tr>" +
                        "<td class='createTime'>" + res.data.records[i].lotNo + "</td>" +
                        "<td class='createTime'>" + res.data.records[i].pinName + "</td>" +
                        "<td class='createTime'>" + res.data.records[i].createTime.replace('T', ' ')  + "</td>" +
                        "<td>" + res.data.records[i].productType     + "</td>" +
                        "<td>" + res.data.records[i].totalAmount + "</td>" +
                        "<td>" + res.data.records[i].acceptAmount + "</td>" +
                        "<td>" + res.data.records[i].childrenNum + "</td>" +
                        "<td>" + res.data.records[i].createBy + "</td>" +
                        "<td id='statusTd' title='点击查看进度'>" + isParentOrderStatus(res.data.records[i].over)+ "</td>" +
                        "<td class='operation'>" +
                        "<button type='button' class='layui-btn layui-btn-warm layui-btn-sm' onclick='listInfo(\"" + res.data.records[i].lotNo + "\")'>详情</button>" +
                        "<button type='button' class='layui-btn layui-btn-normal layui-btn-sm' onclick='edit(\"" + res.data.records[i].lotNo + "\")'>编辑</button>" +
                        "<button type='button' class='layui-btn layui-btn-danger layui-btn-sm ' onclick='deleteOrder(\"" + res.data.records[i].lotNo + "\")'>删除</button></td>" +
                        "</tr>"
                    );
                }
                $('#total').html(Math.ceil(res.data.records[0].allTotal/10))
                $('#page').html(displayStart)
            }
        })
    }
</script>
</body>
</html>